package android.app.gfestival;

import android.app.TabActivity;
import android.app.gfestival.soap.SoapParserHelper;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;

import com.facebook.android.FacebookActivity;

public class GFestival extends TabActivity {
	private TabHost mTabHost;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mTabHost = getTabHost();
        setupTab("Program", ProgramActivity.class, R.drawable.program_tab);
        setupTab("Artist", ArtistActivity.class, R.drawable.artist_tab);
        setupTab("Facebook", FacebookActivity.class, R.drawable.facebook_tab);
        setupTab("News", NewsActivity.class, R.drawable.news_tab);
        setupTab("About", AboutActivity.class, R.drawable.about_tab);
//        SoapParser soapParser = new SoapParser();
//        soapParser.test();
//        soapParser.requestAllEventById(5);
        try {
			SoapParserHelper.getAllEventById("1");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    
    private void setupTab(final String tag, Class<?> clazz, int resid) {
    	Log.i("CreateTabs", "------->" + tag);
    	View tabview = createTabView(mTabHost.getContext(), tag, resid);
    	TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
    	.setContent(new Intent(this, clazz));
    	mTabHost.addTab(setContent);
    }
    
    
	private void setupTab(final View view, final String tag, int resid) {
		View tabview = createTabView(mTabHost.getContext(), tag, resid);

		TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
				.setContent(new TabContentFactory() {
					public View createTabContent(String tag) {
						return view;
					}
				});
		mTabHost.addTab(setContent);

	}

	private static View createTabView(final Context context, final String text, int resid) {
	        View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
	        TextView tv = (TextView) view.findViewById(R.id.tabsText);
	        tv.setText(text);
	        ImageView imageView = (ImageView) view.findViewById(R.id.tabsIcon);
	        imageView.setImageResource(resid);
	        return view;
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyDown(keyCode, event);
		return false;
	}
}